package com.kunchi.platform.controller;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import javagrinko.spring.tcp.Connection;
import javagrinko.spring.tcp.TcpController;

@TcpController
public class TcpReceiverController {

  private static final Logger logger = LoggerFactory.getLogger(TcpReceiverController.class);

  public void receiveData(Connection connection, byte[] data) {
    String s = new String(data);
    logger.info("[{}] Receive data: {}", connection.getAddress().getHostAddress(), s);
    connection.send(s.toUpperCase().getBytes());
  }

  public void connect(Connection connection) {
//    logger.info("New connection " + connection.getAddress().getCanonicalHostName());
  }

  public void disconnect(Connection connection) {
//    logger.info("Disconnect " + connection.getAddress().getCanonicalHostName());
  }
}
